package com.atguigu.day211105.work;

public class CreditCard extends BankCard {
    private double amount;

    public CreditCard() {
    }

    public CreditCard(int id, double balance, double amount) {
        super(id, balance);
        this.amount = amount;
    }

    public double getAmount() {
        return amount;
    }

    @Override
    public void withdraw(double money) {
        if (money <= getBalance()) {
            super.withdraw(money);
        } else if (money > getBalance()) {
            if (money <= getBalance() + amount) {
                amount = money - getBalance();
                super.withdraw(getBalance());
            } else {
                System.out.println("超过可透支额度");
            }
        }
    }

    @Override
    public void save(double money) {
        if (amount == 0) {
            super.save(money);
        } else if (money <= amount) {
            amount -= money;
        } else {
            super.save(money - amount);
            amount = 0;
        }
    }

    @Override
    public String getInfo() {
        return super.getInfo() + ",已透支金额:" + amount;
    }
}
